import { getToken } from '@/utils/storage'
import { applyMiddleware, createStore } from 'redux'
import { composeWithDevTools } from 'redux-devtools-extension'
import thunk from 'redux-thunk'
import reducer from './reducers'

let middlewares
if (process.env.NODE_ENV === 'production') {
  middlewares = applyMiddleware(thunk)
} else {
  middlewares = composeWithDevTools(applyMiddleware(thunk))
}
const store = createStore(
  reducer,
  {
    login: {
      token: getToken(),
    },
  },
  middlewares
)

export default store
